#include "expfail.h"
#include "ui_expfail.h"
#include "userlogger.h"
#include "buzzer.h"
#include "project.h"
#include "shadow.h"

ExpFail::ExpFail(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::ExpFail)
{
    ui->setupUi(this);
    connect(BllDataFlow::getInstance(), &BllDataFlow::retranslateUiSignal, this, &ExpFail::retranslateUiSlot);

    if (windowWidth >= 1280) {
        setGeometry(0,0,1280,800);
        setProperty("cssSize","large");
        ui->widget_2->setMinimumHeight(66);
        ui->widget_3->setMinimumHeight(80);
    }

    setParent(Project::Instance());
    setAttribute(Qt::WA_TranslucentBackground, true);
    QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect();
    shadow->setColor(QColor(0,0,0,150));
    shadow->setOffset(1, 1);
    shadow->setBlurRadius(16);
    ui->widget->setGraphicsEffect(shadow);
    setWindowFlags(windowFlags() | Qt::SubWindow);
}

ExpFail::~ExpFail()
{
    delete ui;
}

ExpFail::DialogCode ExpFail::show(const HostReply &result)
{
    if ("HP2STR03" != result.cmd)
    {
        ui->btnOK->show();
        ui->btnStop->hide();
        ui->btnContinue->hide();
        UserLogger::error(result.message);
    }
    else
    {
        ui->btnOK->hide();
        ui->btnStop->show();
        ui->btnContinue->show();
    }

    ui->lblExpError->setText(result.message);
    ui->lblTips->setText(result.tips.isEmpty() ? tr("Please Suspend Use and Contact Engineer") : result.tips);
    Buzzer::instance()->start();
    return (DialogCode)QDialog::exec();
}


void ExpFail::on_btnOK_clicked()
{
    Buzzer::instance()->stop();
    this->accept();
}

void ExpFail::on_btnStop_clicked()
{
    Buzzer::instance()->stop();
    this->accept();
}

void ExpFail::on_btnContinue_clicked()
{
    Buzzer::instance()->stop();
    this->reject();
}

void ExpFail::retranslateUiSlot()
{
    ui->retranslateUi(this);
}
